from cassandra.cluster import Cluster
cluster = Cluster(['192.168.209.200'])

session = cluster.connect()
try:
    session.execute("drop keyspace  ks1")
    session.execute("CREATE KEYSPACE ks1 WITH REPLICATION = {'class' :'SimpleStrategy', 'replication_factor':1};")
except Exception as err:
    print(err)


session.execute("use ks1")
try:
    session.execute("create table users(id int, name text, primary key(id));")
except Exception as err:
    print(err)

session.execute("insert into users(id, name) values(1, 'ZHR');")
session.execute("insert into users(id, name) values(2, 'LM');")
session.execute("insert into users(id, name) values(3, 'Lj');")
rows = session.execute('select * from users')
print(rows[0].id)
for r in rows:
    print(r)
# row.id

session.execute("delete from users where id=5")  
rows = session.execute('select * from users')
data = rows[0]

session.execute("insert into users(id, name) values(4, 'Naruo');")
rows = session.execute('select * from users')
data = rows[0]
print(data)
session.shutdown()
cluster.shutdown()

'''
官方文档
https://docs.datastax.com/en/developer/python-driver/3.29/index.html
'''




